<template>
	<div class="page-container">
		<el-card class="page-form-card">
			<div>
				<l-back class="mb-[20px]" />
				<el-form ref="ruleForm" label-position="left" :model="form" label-width="90px" class="form">
					<el-form-item label="最低提现金额:">
						<el-input v-model="form.minWithdraw" class="!w-[204px]"></el-input>
					</el-form-item>
					<el-form-item label="最低保留金额:">
						<el-input v-model="form.minKeep" class="!w-[204px]"></el-input>
					</el-form-item>
					<el-form-item label="手续费(%):">
						<el-input-number v-model="form.handlingFee" :step="1" :min="0" :max="100"></el-input-number>
					</el-form-item>
					<el-form-item label="只能整百提现:">
						<el-switch v-model="form.type" active-color="#13ce66" inactive-color="#ff4949"> </el-switch>
					</el-form-item>

					<el-form-item>
						<el-button class="!w-[107px] !h-[40px]" type="primary" @click="submit">提交</el-button>
					</el-form-item>
				</el-form>
			</div>
		</el-card>
	</div>
</template>

<script>
import { getSettingInfo, editSettingInfo, addSettingInfo } from '@/api/mall/withdraw';
export default {
	name: 'Index',
	data() {
		return {
			form: {
				topupType: 1,
				num: 1,
				type: 1,
				id: null,
				remark: '',
				handlingFee: 0,
				userType: '店铺',
			},
			mobile: '',
			flag: false,
		};
	},
	created() {
		this.getSettingInfo();
	},
	methods: {
		returnAduit() {
			this.$router.push('withdrawAuditStore');
		},
		submit() {
			this.form.isHundredWithdraw = this.form.type ? 1 : 0;
			if (this.form.type) {
				if (this.form.minWithdraw < 100) {
					this.$message.error('整百提现最低提现金额不少于100');
					return;
				}
			}
			let obj = JSON.parse(JSON.stringify(this.form));
			obj.type = 2;
			obj.handlingFee = this.form.handlingFee / 100;
			if (this.form.id != null) {
				editSettingInfo(obj).then(() => {
					this.$message.success('更新成功');
					this.getSettingInfo(obj);
				});
			} else {
				addSettingInfo(obj).then(() => {
					this.$message.success('新增成功');
					this.getSettingInfo(obj);
				});
			}
		},
		getSettingInfo() {
			getSettingInfo({
				pageSize: 1,
				pageNum: 1,
				type: 2,
				userType: '店铺',
			}).then((res) => {
				this.form = {
					id: res.data.records[0].id,
					minKeep: res.data.records[0].minKeep,
					minWithdraw: res.data.records[0].minWithdraw,
					handlingFee: res.data.records[0].handlingFee * 100,
					type: res.data.records[0].isHundredWithdraw == 1 ? true : false,
				};
			});
		},
		submitForm() {},
	},
};
</script>

<style scoped lang="scss">
.app-container {
	background: #f7f7f7;
	height: 100vh;
	.btn-return {
		margin-bottom: 10px;
	}
}
.content {
	max-width: 1624px;
	min-width: 600px;
	height: 679px;
	background: #ffffff;
	box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.04);
	opacity: 1;
	border-radius: 8px;
	.form {
		width: 600px;
		margin: 40px auto 0;
		.tips {
			height: 31px;
			background: #f7f7f7;
			border-radius: 0px 0px 4px 4px;
			line-height: 31px;
			color: #f14a46;
			padding-left: 16px;
			span {
				color: #808a97;
			}
		}
		.btn {
			margin: 0 auto;
			width: 321px;
			height: 44px;
			background: #6373ee;
			border-radius: 4px;
			font-size: 14px;
			color: #ffffff;
			line-height: 44px;
			text-align: center;
			cursor: pointer;
		}
	}
	.title {
		font-size: 18px;
		font-weight: bold;
		padding-left: 26px;
		padding-top: 25px;
	}
}
</style>
